package com.zpz.framework.zpzoauth.common.utils;

import com.alibaba.fastjson.JSON;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;

import java.io.IOException;
import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.Map;

public class MsgUtils {
    public static String MSGURL;
    @Value("${zpzOauth.msg.url}")
    public void setApplicationName(String msgUrl){
        MSGURL=msgUrl;
    }

    public static boolean validateMsgCode(String phone,String code) {
        try {
            Map<String,String> param=new HashMap<>();
            param.put("phone",phone);
            param.put("validateContent",code);
            String resultStr = ZpzOauthHttpUtil.getInstance().doPostJsonString(MSGURL, null, JSON.toJSONString(param), null);
            if (StringUtils.isNotBlank(resultStr)){
                Map<String,Object> re=(Map<String,Object>)JSON.parse(resultStr);
                Object _code = re.get("code");
                if (_code!=null&&Integer.parseInt(_code.toString())==0){
                    return true;
                }
            }
            System.out.println(resultStr);
        } catch (URISyntaxException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return false;

    }
}
